package demo1;

public class Computer {
    public void open(){
        System.out.println("开机！");
    }
    public void close(){
        System.out.println("关机！");
    }
    public void useDevice(IUSB usb){
        usb.openDevice();
        if(usb instanceof Mouse){
            Mouse mouse2 = new Mouse();
            mouse2.click();
            //Mouse mouse = (Mouse)usb;
            //mouse.click();//个人觉得没必要向下转型，向下转型有风险
        }else if(usb instanceof KeyBoard){
            KeyBoard keyBoard = (KeyBoard)usb;
            keyBoard.closeDevice();
        }
        usb.closeDevice();
    }
}
